import 'package:flutter/material.dart';

class GridViewCase extends StatelessWidget {
  const GridViewCase({Key? key}) : super(key: key);

  List<Widget> getList() {
    return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((int i) {
      return Container(
        alignment: Alignment.center,
        margin: const EdgeInsets.all(10),
        decoration: const BoxDecoration(
          color: Colors.blue,
          borderRadius: BorderRadius.all(Radius.circular(10)),
        ),
        width: double.infinity,
        height: 100,
        child: Text("我是第$i个"),
      );
    }).toList();
  }

  @override
  Widget build(BuildContext context) {
    return GridView(
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 3, // 3列
          mainAxisSpacing: 10, // 主轴间隔
          crossAxisSpacing: 10, // 纵轴间隔
          childAspectRatio: 1 // 宽高比
          ),
      children: getList(),
    );
  }
}
